package com.usian.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usian.article.mapper.ApArticleConfigMapper;
import com.usian.article.mapper.ApArticleContentMapper;
import com.usian.article.service.ArticleInfoService;
import com.usian.model.article.dtos.ArticleInfoDto;
import com.usian.model.article.pojos.ApArticleConfig;
import com.usian.model.article.pojos.ApArticleContent;
import com.usian.model.base.BaseServiceImpl;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ArticleInfoServiceImpl extends BaseServiceImpl<ApArticleContentMapper, ApArticleContent> implements ArticleInfoService {

    @Autowired
    private ApArticleConfigMapper configMapper ;
    @Override
    public ResponseResult loadArticleInfo(ArticleInfoDto dto) {
        if (dto==null || dto.getArticleId()==null)return errorParam;
        Map<String,Object>map= new HashMap<>();
      ApArticleConfig config= configMapper.selectOne(getWrapper(dto.getArticleId()));
       if (!config.getIsDelete()&&config.getIsDown()) {
           ApArticleContent content = baseMapper.selectOne(getWrapper(dto.getArticleId()));
           map.put("config", config);
           map.put("content", content);
       }
        return ResponseResult.okResult(map);
    }

    private QueryWrapper getWrapper(Long articleId){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("article_id",articleId);
        return wrapper;
    }
}
